<?php
include('../../include/functions.inc.php');
include('../../include/inputbuilder.inc.php');
include('../../include/maintenance.inc.php');
if (isEmpty(getParam('USER_NAME'))) {
    echo 'WRONG PARAMETER';
} else {
    $maintenance = unserialize($_SESSION['mUser']);
    $list = $db->query_select("cllg_entity", NULL);
    $list2 = $db->query_select("cllg_perfil", NULL);
    $rows = $db->query_select($maintenance->table, sprintf("USER_NAME='%s'", getParam('USER_NAME')));

    foreach ($rows as $row) {
        ?>
        <form id="<?php echo $maintenance->formName; ?>" name="<?php echo $maintenance->formName; ?>" method="POST" action="<?php echo $maintenance->updateUrlPage; ?>">
            <table class=""  width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <th scope="col"><legend>DATOS USUARIO</legend></th>
                    <th scope="col">
                    <legend>
                        <div style="margin-left: 30%" class="btn-group">
                        <input type="button" name="cmdOk" class="btn btn-info" id="cmdOk" value="Guardar" onClick="javascript:formOkBt($(this.form),updateAction);" />
                        <input type="button" name="eliminar" id="eliminar" class="btn btn-info" onclick="javascript:deleteAction('<?php echo $maintenance->deleteUrlPage; ?>',<?php echo $maintenance->getDeleteUrl(); ?>)" value="Eliminar" />        
                        <input type="button" class="btn btn-info" name="cmdCancel" id="cmdCancel" value="Cancelar" onClick="loadTable();jQuery('#cmAddcontainer').show();" />
                        </div>
                    </legend>     
                    </th>
                </tr>
                <tr>
                    <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">

                            <tr>
                                <td width="20%">* USUARIO</td>
                                <td width="80%"><input name="USER_NAME" type="text" id="USER_NAME" value="<?php echo $row['USER_NAME']; ?>" />          </td>
                            </tr>

                            <tr>
                                <td>NOMBRES</td>
                                <td><input name="FIRST_NAME" type="text" id="FIRST_NAME" value="<?php echo $row['FIRST_NAME']; ?>" /></td>
                            </tr>
                            <tr>
                                <td>APELLIDOS</td>
                                <td><input name="LAST_NAME" type="text" id="LAST_NAME" value="<?php echo $row['LAST_NAME']; ?>" /></td>
                            </tr>
                            <tr>
                                <td>ENTIDAD</td>
                                <td><select name="FK_ENTITY" id="FK_ENTITY">
                                        <?php foreach ($list as $it) { ?>
                                            <option value="<?php echo $it["ID"]; ?>" 
                                            <?php
                                            if (!(strcmp($it["ID"], $row['FK_ENTITY']))) {
                                                echo "selected=\"selected\"";
                                            }
                                            ?>> <?php echo $it["NAME"]; ?> </option>
        <?php } ?>
                                    </select></td>
                            </tr>
                            <tr>
                                <td>* PERFIL USUARIO</td>
                                <td><select name="FK_PERFIL" id="FK_PERFIL">
                                        <?php foreach ($list2 as $it) { ?>
                                            <option value="<?php echo $it["ID"]; ?>" 
                                                    <?php
                                                    if (!(strcmp($it["ID"], $row['FK_PERFIL']))) {
                                                        echo "selected=\"selected\"";
                                                    }
                                                    ?>> <?php echo $it["NAME"]; ?> </option>
        <?php } ?>
                                    </select></td>
                            </tr>
                            <tr>
                                <td>ESTADO</td>
                                <td><select name="STATUS" id="STATUS">
                                        <option value="1" <?php
        if (!(strcmp(1, $row['STATUS']))) {
            echo "selected=\"selected\"";
        }
        ?>>ACTIVO</option>
                                        <option value="0" <?php
        if (!(strcmp(0, $row['STATUS']))) {
            echo "selected=\"selected\"";
        }
        ?>>INACTIVO</option>
                                    </select></td>
                            </tr>
                            <tr>
                                <td>* CONTRASE&Ntilde;A</td>
                                <td><input name="PASSWORD" readonly="readonly" value="<?php echo $row["PASSWORD"]; ?>" type="password" id="PASSWORD" /></td>
                            </tr>
                            <tr>
                                <td>PUEDE AUTORIZAR </td>
                                <td><select name="AUTORIZA" id="AUTORIZA">
                                        <option value="1" <?php
        if (!(strcmp(1, $row["AUTORIZA"]))) {
            echo "selected=\"selected\"";
        }
        ?>>SI</option>
                                        <option value="0" <?php
        if (!(strcmp(0, $row["AUTORIZA"]))) {
            echo "selected=\"selected\"";
        }
        ?>>NO</option>
                                    </select></td>
                            </tr>

                        </table></td>
                </tr>
                <tr>
                    <th colspan="2"><legend>CAMBIO DE CONTRASE&Ntilde;A</legend></th>
                </tr>
                <tr>
                    <td colspan="2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="20%">NUEVA CONTRASE&Ntilde;A</td>
                                <td width="80%"><input type="password" name="NEWPASS" id="NEWPASS" /></td>
                            </tr>
                            <tr>
                                <td>REPETIR CONTRASE&Ntilde;A</td>
                                <td><input type="password" name="NEWPASS2" id="NEWPASS2" /></td>
                            </tr>
                        </table></td>
                </tr>
            </table>
        </form>  
        <?php
    }
}
?>
